<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb>
      <el-breadcrumb-item>成员事件录入</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 表单输入 -->
    <div class="SFormBox">
      <el-form ref="SFRef" :model="SForm" :rules="SFormRules" class="SForm_sty">
        <el-form-item prop="s_id">
          <el-input v-model="SForm.id">
            <template slot="prepend">事件ID</template>
          </el-input>
        </el-form-item>
                <el-form-item prop="s_pid">
          <el-input v-model="SForm.pid">
            <template slot="prepend">人员ID</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="s_name">
          <el-input v-model="SForm.name">
            <template slot="prepend">姓名</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="s_time">
          <el-input v-model="SForm.time">
            <template slot="prepend">发生日期</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="s_type">
          <el-input v-model="SForm.type">
            <template slot="prepend">事件类型</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="s_about">
          <el-input v-model="SForm.about">
            <template slot="prepend">事件描述</template>
          </el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="inserUser" round>录入</el-button>
          <el-button type="info" @click="resetuserForm" round>重置</el-button>
        </el-form-item>
      </el-form>
      <!-- 提交弹窗 -->
      <el-dialog title="提示" :visible.sync="sucessVisible" width="30%">
        <span>确定录入？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="sucessVisible = false">取 消</el-button>
          <el-button type="primary" @click="sucessVisible = false">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      SForm: {
        id: '',
        pid: '',
        name: '',
        time: '',
        type: '',
        about: ''
      },
      // 输入规则
      userFormRules: {
        userid: [
          { required: true, message: '请输入事件ID', trigger: 'blur' }
        ],
        pid: [
          { required: true, message: '请输入人员ID', trigger: 'blur' }
        ],
        username: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        birth: [
          { required: true, message: '请输入发生日期', trigger: 'blur' }
        ],
        introduce: [
          { required: true, message: '请输入事件类型', trigger: 'blur' }
        ],
        death: [
          { required: true, message: '请输入事件描述', trigger: 'blur' }
        ]

      },
      sucessVisible: false
    }
  },
  methods: {
    // 校验规则
    resetuserForm() {
      this.$refs.userFormRef.resetFields()
    },
    // 提交用户
    inserUser() {
      const { data: res } = this.$http.post('story', {
        s_id: this.SForm.id,
        s_pid: this.SForm.pid,
        s_name: this.SForm.name,
        s_time: this.SForm.time,
        s_type: this.SForm.type,
        s_about: this.SForm.about
      })
      this.emidtsucess()
      console.log(res)
    },
    // 提交成功提示
    emidtsucess() {
      this.sucessVisible = true
    }
  }
}
</script>

<style lang="less" scoped>
.el-form-item {
  width: 500px;
}

.UserFormBox {
  background-color: #fffffb;
  height: 600px;
  width: 1210px;
  border-radius: 5px;
  margin-left: 10px;
}

.UserForm_sty {
  position: absolute;
  padding: 30px 60px 30px;
  box-sizing: border-box;
}

.btns {
  display: flex;
  justify-content: flex-start;
  margin-top: 60px;
}
</style>
